﻿/*
 * Created by SharpDevelop.
 * User: 1987wing
 * Date: 2016/9/6
 * Time: 23:38
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using Fiddler;

using System.Collections.Generic;
using System.Windows.Forms;

[assembly: Fiddler.RequiredVersion("2.3.5.0")]

namespace BuriedPointsForYMT
{
	/// <summary>
	/// Description of MyClass.
	/// </summary>
	public class Main : IAutoTamper
	{
		private BuriedPointsTabPage oPage;
		private AutoTamperReqBeforeHandler request;
		
		public Main()
        {
            /* NOTE: It's possible that Fiddler UI isn't fully loaded yet, so don't add any UI in the constructor.

               But it's also possible that AutoTamper* methods are called before OnLoad (below), so be
               sure any needed data structures are initialized to safe values here in this constructor */   
        }
		
		public void OnLoad() 
        { 
            /* Load your UI here */
            oPage = new BuriedPointsTabPage();
           
            FiddlerApplication.UI.tabsViews.TabPages.Add(oPage);
        }
		
		public void OnBeforeUnload() { }
		
		public void AutoTamperRequestBefore(Session oSession) 
		{
        	if (this.oPage == null) return;

        	if (!oSession.host.Equals("ymtlog.ymatou.com")) return;
        	
        	if (!oPage.get_switch_checkbox().Checked) return;
        	request = new AutoTamperReqBeforeHandler(oSession, oPage);
        	request.udpateSessionList();
        }
		
		public void AutoTamperRequestAfter(Session oSession) { }

        public void AutoTamperResponseBefore(Session oSession){
			
			if (this.oPage == null) return;

        	if (!oSession.host.Equals("ymtlog.ymatou.com")) return;
        	
        	if (!oPage.get_switch_checkbox().Checked) return;
        	
			oSession.ResponseBody = System.Text.Encoding.UTF8.GetBytes(request.getResponseBody());
		}
        public void AutoTamperResponseAfter(Session oSession) { }
        public void OnBeforeReturningError(Session oSession) { }
	}
}